package com.kfm.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dispatcher")
public class DispatcherServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("DispatcherServlet 处理了请求，并存了一个 name ");
        req.setAttribute("name", "zhangsan");

        // 请求转发
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/test");
        requestDispatcher.forward(req, resp);

    }
}
